﻿using System;
using System.Collections.Generic;
using Framework.Message.SMS.CMPP.Commands;

namespace Framework.Message.SMS.CMPP
{
    public class CommandFactory
    {
        public static Command GetCommandFormByte(byte[] bytes)
        {
            CMPPCommandType commandType = (CMPPCommandType)ByteIntConvert.Bytes2UInt(bytes, 4);
            switch (commandType)
            {
                case CMPPCommandType.Connect:
                    return new ConnectCommand(bytes);
                case CMPPCommandType.Connect_Resp:
                    return new ConnectRespCommand(bytes);
                case CMPPCommandType.Terminate:
                    return null;
                case CMPPCommandType.Terminate_Resp:
                    return null;
                case CMPPCommandType.Submit:
                    return null;
                case CMPPCommandType.Submit_Resp:
                    return null;
                case CMPPCommandType.Deliver:
                    return null;
                case CMPPCommandType.Deliver_Resp:
                    return null;
                case CMPPCommandType.Query:
                    return null;
                case CMPPCommandType.Query_Resp:
                    return null;
                case CMPPCommandType.Cancel:
                    return null;
                case CMPPCommandType.Cancel_Resp:
                    return null;
                case CMPPCommandType.Active_Test:
                    return new ActiveTestCommand(bytes);
                case CMPPCommandType.Active_Test_Resp:
                    return new ActiveTestRespCommand(bytes);
                default:
                    return null;
            }
        }

        public static Command GetNewCommand(CMPPCommandType commandType, uint sequence)
        {
            switch (commandType)
            {
                case CMPPCommandType.Connect:
                    return new ConnectCommand(sequence);
                case CMPPCommandType.Connect_Resp:
                    return new ConnectRespCommand(sequence);
                case CMPPCommandType.Terminate:
                    return null;
                case CMPPCommandType.Terminate_Resp:
                    return null;
                case CMPPCommandType.Submit:
                    return null;
                case CMPPCommandType.Submit_Resp:
                    return null;
                case CMPPCommandType.Deliver:
                    return null;
                case CMPPCommandType.Deliver_Resp:
                    return null;
                case CMPPCommandType.Query:
                    return null;
                case CMPPCommandType.Query_Resp:
                    return null;
                case CMPPCommandType.Cancel:
                    return null;
                case CMPPCommandType.Cancel_Resp:
                    return null;
                case CMPPCommandType.Active_Test:
                    return new ActiveTestCommand(sequence);
                case CMPPCommandType.Active_Test_Resp:
                    return new ActiveTestRespCommand(sequence);
                default:
                    return null;
            }
        }

        public static CommandT GetNewCommand<CommandT>(uint sequence) where CommandT : Command, new()
        {
            CommandT command = new CommandT();
            command.Header.SequenceNumber = sequence;
            return command;
        }

    }
}
